package com.mytrans.config;

import com.mytrans.aspect.TranceAspect;
import com.mytrans.client.MytransServerClient;
import com.mytrans.client.RibbonClient;
import com.mytrans.transaction.TokenManager;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpServlet;

@Configuration
public class TransConfiguration {

    @Bean
    public ServletRegistrationBean statViewServle(MytransConfig mytransConfig){
        HttpServlet httpServlet = mytransConfig.getTransactionManagerClient().getServlet();
        return new ServletRegistrationBean(httpServlet, "/druid/*");
    }

    @Bean
    public TranceAspect tranceAspect(){
        return new TranceAspect();
    }

    @Bean
    public TokenManager tokenManager(MytransConfig mytransConfig){
        return mytransConfig.getTokenManager();
    }

    @Bean
    public MytransServerClient mytransServerClient(){
        return new MytransServerClient();
    }

    @Bean
    public RibbonClient ribbonClient(){
        return new RibbonClient();
    }

}
